{extend name="platform/base" /}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 添加推广员等级 </header>
	<div class="panel-body">
		<form class="form-horizontal" id="level_form" name="form">
			<div class="form-group">
				<label class="col-sm-2 control-label">等级名称</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="level_name" name="level_name" value="" >
				</div>
				<p class="error" style="display:none;">请输入大于0小于等于100的两位的数值,最多保留俩位小数！</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">升级条件</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="level_money" name="level_money" value="" onkeyup="javascript:CheckInputIntFloat(this);">
				</div>
				<label class="col-md-8 error" for="level_money" ></label>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">本店销售佣金比率（%）</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="level_0" value="" onkeyup="javascript:CheckInputIntFloat(this);">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">给上级的佣金比率（%）</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="level_1" value="" onkeyup="javascript:CheckInputIntFloat(this);">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">给上上级的佣金比率（%）</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="level_2" value="" onkeyup="javascript:CheckInputIntFloat(this);">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<button type="submit" class="btn btn-primary">保存</button>
				</div>
			</div>
		</form>
	</div>
</section>
<script src="__STATIC__/js/limit_input_digit.js"></script>
<script>
$().ready(function() {
	$("#level_form").validate({
		submitHandler:function(){
			addPromoterLevel();
		}
	});
});
	function addPromoterLevel(){
		var level_name = $("#level_name").val();
		var level_money = $("#level_money").val();
		var level_0 = $("#level_0").val();
		var level_1 = $("#level_1").val();
		var level_2 = $("#level_2").val();
		if(level_name == ""){
			$("#level_name").parent().next().show();
			return false;
		}else{
			$("#level_name").parent().next().hide();
		}
		if((parseFloat(level_0) +parseFloat(level_1)+ parseFloat(level_2))>100 ){
			showMessage('error', "佣金比率不可超过100%！");	
			return false;
		}
		$.ajax({
			type:"post",
			url:"{:__URL('PLATFORM_MAIN/Distribution/addPromoterLevel')}",
			data:{
				'level_name':level_name,
				'level_money':level_money,
				'level_0':level_0,
				'level_1':level_1,
				'level_2':level_2
			},
			async:true,
			success:function (data) {
				//alert(data);
				if (data["code"] > 0) {
					showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/Distribution/PromoterLevelList')}");
				}else{
					showMessage('error', data["message"]);
				}	
			}
		});
	}
</script>
{/block}